class Messages {
  showMessage(message) {
    wx.showToast({
      title: message,
      icon: 'success',
    });
  }

  showError(error) {
    const errorMessage = error.errMsg || error.msg || error || '系统异常';
    wx.showToast({
      title: errorMessage,
      icon: 'error',
    });
  }

  showModal(message) {
    return new Promise((resole, reject) => {
      wx.showModal({
        title: '提示',
        content: message,
        success(res) {
          if (res.confirm) {
            resole(res);
          } else if (res.cancel) {
            reject('');
          }
        },
        fail: reject,
      });
    });
  }
}

const instance = new Messages();
module.exports = instance;
